iT邦幫忙

2024 iThome 鐵人賽

DAY 3
0
Python

30天零基礎學習Python程式語言系列 第 3

Day 3: 型別轉換 + 使用者輸入

  • 分享至 

  • xImage
  •  

型別轉換type casting分為兩種方式如下:

  • 顯示:下圖顯示三種不同型別轉換。
  1. 原為int資料型別的age轉換為float資料型別
  2. 原為float資料型別的gpa轉換為int資料型別(四捨五入)
  3. 原為boolean資料型別的student轉換為string資料型別

https://ithelp.ithome.com.tw/upload/images/20240909/201691446EiVlnQeBX.png

https://ithelp.ithome.com.tw/upload/images/20240909/20169144Rhk9JeE79c.png

  • 隱式:資料因運算過程自動型別轉換,不需打出code
    https://ithelp.ithome.com.tw/upload/images/20240909/20169144tEKd8zs2bn.png
    https://ithelp.ithome.com.tw/upload/images/20240909/20169144UqiBlu7vPC.png

使用者輸入:
使用input將資料輸入,並放入特定位置當中輸出,以下四種練習

  1. 取得名字:
    https://ithelp.ithome.com.tw/upload/images/20240909/201691443j5MeqTvXQ.png
  2. 填詞遊戲:
    https://ithelp.ithome.com.tw/upload/images/20240909/20169144MfXozs5p2O.png
  3. 計算矩形的面積:
    https://ithelp.ithome.com.tw/upload/images/20240909/20169144XSeXvCZQu9.png
  4. 購物車程式:
    https://ithelp.ithome.com.tw/upload/images/20240909/20169144foBUHlUOBx.png

上一篇
Day 2: 變數與資料型別
下一篇
Day 4: 數學方法
系列文
30天零基礎學習Python程式語言21
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言